// -*- c++ -*-
/**************************************************************/
/*  This file is licensed from, and is a trade secret of:     */
/*                                                            */
/*    Mercury Computer Systems, Incorporated                  */
/*    199 Riverneck Road                                      */
/*    Chelmsford, Massachusetts 01824-2820                    */
/*    United States of America                                */
/*    Telephone + 1 978 256-1300                              */
/*                                                            */
/*  Refer to your Software License Agreement for provisions   */
/*  on use, duplication, or disclosure.                       */
/*  US. Government users and prime contractors are also       */
/*  governed by the following Data Rights Notice:             */
/*  Use, duplication or disclosure by the US. Government is   */
/*  subject to the provisions set forth in FAR 52.227-14 for  */
/*  restricted rights or other agency data rights provisions  */
/*  on commercial software and documentation, as applicable.  */
/*                                                            */
/*  This file: (a) was developed at private expense, and no   */
/*  part was developed with government funds, (b) is a        */
/*  trade secret of Mercury Computer Systems, Inc. for the    */
/*  purposes of the Freedom of Information Act, (c) is        */
/*  "commercial computer software" subject to limited         */
/*  utilization as provided in the above noted Software       */
/*  License Agreement and (d) is in all respects data         */
/*  belonging exclusively to Mercury Computer Systems, Inc..  */
/*                                                            */
/**************************************************************/

/******************************************************************/
/* Copyright (c) 1999-2003, Mercury Computer Systems, Inc.,       */
/* Chelmsford MA.,and all third party embedded software sources.  */
/* All rights reserved under the Copyright laws of US. and        */
/* international treaties.                                        */
/*                                                                */
/* Patent Pending                                                 */
/******************************************************************/


//$COPYRIGHT_END

#ifndef RsHop_H__
#define RsHop_H__

#include <iostream>
#include <string>
#include "CF__Resource_impl.h"
#include "AudioPort_impl.h"
#include "SceOsSemaphore.h"
#include "SceOsThreadManager.h"
#include "mc_error.h"

#include "GaloisField.h"
#include "GaloisFieldElement.h" 
#include "GaloisFieldPolynomial.h"


#ifdef _WIN32
#ifdef RSHOP_EXPORTS
#define RSHOP_EXPORT __declspec(dllexport)
#else
#define RSHOP_EXPORT __declspec(dllimport)
#endif
#else
#define RSHOP_EXPORT 
#endif


class RSHOP_EXPORT RsHopEncoder : public CF__Resource_impl {
public: 
  static status
  Create (RsHopEncoder *& ModulatorHandle,
	  const char * identifier);

  status Run ();
  static void RunWorker (void * param);
  status RunLoop ();

  // From CF::Resource
  void start ()
    throw (CORBA::SystemException, CF::Resource::StartError);
  void stop ()
    throw (CORBA::SystemException, CF::Resource::StopError);

  // From CF::PortSupplier
  CORBA::Object_ptr getPort (const CORBA::Char * name)
    throw (CORBA::SystemException, CF::PortSupplier::UnknownPort);

private:
  RsHopEncoder (const char * identifier);
  ~RsHopEncoder ();

  status Init ();

  // Port definitions.
  BitPacketizerInPort_impl * m_rshopin;
  RsHopOutPort_impl * m_rshopout;

  char * m_input;
  char * m_output;

  bool m_bStop;
  bool m_threadrunning;
  SCE::OS::ThreadManager m_thread;

  unsigned int m_n, m_k, m_N, m_K, m_m, m_b, m_t;
  galois::GaloisField * m_gf;
  galois::GaloisFieldPolynomial * m_genpoly;
  galois::GaloisFieldPolynomial * m_encMsg;
};


class RSHOP_EXPORT RsHopDecoder : public CF__Resource_impl {
public:
  static status
  Create (RsHopDecoder *& DemodHandle,
	  const char * identifier);

  status Run ();
  static void RunWorker (void * param);
  status RunLoop ();

  // From CF::Resource
  void start ()
    throw (CORBA::SystemException, CF::Resource::StartError);
  void stop ()
    throw (CORBA::SystemException, CF::Resource::StopError);

  // From CF::PortSupplier
  CORBA::Object_ptr getPort (const CORBA::Char * name)
    throw (CORBA::SystemException, CF::PortSupplier::UnknownPort);

private:
  RsHopDecoder (const char *identifier);
  ~RsHopDecoder ();

  status Init ();

  // Port definitions
  RsHopInPort_impl * m_rshopin;
  BitPacketizerOutPort_impl * m_rshopout;

  char * m_input;
  char * m_output;
  unsigned int m_output_count;

  bool m_bStop;
  bool m_threadrunning;
  SCE::OS::ThreadManager m_thread;

  unsigned int m_n, m_k, m_N, m_K, m_m, m_b, m_t;
  galois::GaloisField * m_gf;
  galois::GaloisFieldPolynomial * m_decMsg;
};

#endif /* RsHop_H */


